package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.entity.vo.*;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author : ssy
 * @date: 2024-04-26
 * @Description:
 */
public interface CommonMapper {
    @DS("dscsys")
    @Select("Select MF004 FROM ADMMF where MF001 = #{creator}")
    String getUsrGroup(String creator);

    @DS("dscsys")
    @Select("SELECT TOP 1 ML001 FROM CMSML")
    String getCompany();

    @DS("demo")
    @Select("SELECT MAX(${last}) FROM ${database} WHERE ${last} BETWEEN CONVERT(VARCHAR(8), GETDATE(), 112)+'001' AND CONVERT(VARCHAR(8), GETDATE(), 112)+'999' AND ${first} = #{db}")
    Long getDH2(String database, String last,String first,String db);

    @DS("demo")
    @Select("SELECT MAX(${last}) FROM ${database} WHERE ${last} BETWEEN CONVERT(VARCHAR(8), GETDATE(), 112)+'001' AND CONVERT(VARCHAR(8), GETDATE(), 112)+'999'")
    Long getDH(String database, String last);

    @Select("SELECT ME001 deptNo,ME002 deptName FROM CMSME " +
            "WHERE ME001 LIKE CONCAT('%',#{deptNo},'%')" +
            "AND ME002 LIKE CONCAT('%',#{deptName},'%') ")
    List<DeptVo> getDept(String deptNo, String deptName);

    @Select("SELECT MV001 empNo,MV002 empName FROM CMSMV " +
            "WHERE MV001 LIKE CONCAT('%',#{empNo},'%')" +
            "AND MV002 LIKE CONCAT('%',#{empName},'%')")
    List<EmpVo> getEmp(String empNo, String empName);

    List<LotVo> getLot(String orderNo, String stashNo);

    @Select("SELECT MB022,MB127,MB023,MB024,MB017 FROM INVMB WHERE MB001 = #{orderNo}")
    Map<String,Object> isLot(String orderNo);

    @Select("Select NA002,NA003\n" +
            "  from  CMSNA\n" +
            "  where NA001 = #{type}")
    List<PaymentTerms> getAllPaymentTerms(String type);

    List<CustomerInfoVo> getCustomercInfos(String code);

    List<String> getFactoryAll();

    @Select("SELECT MA094 FROM CMSMA")
    String getRuleByLotSplit();

    List<LotVo> lotSplit(String rule,String orderNo,String stashNo);
}
